<template>
    <view class="local-bar">
        <view>
            本地时间:<text class="local-date">{{ localDateStr }}</text>
            <text class="local-time">{{ localTimeStr }}</text>
            &nbsp;&nbsp;北京时间:<text class="local-date">{{ beijinDateStr }}</text>
            <text class="local-time">{{ beijinTimeStr }}</text>
        </view>
        <view v-if="sumRiseTimeStr">
            日出:<text class="sun-time">{{ sumRiseTimeStr }}</text>
            日落:<text class="sun-time">{{ sumSetTimeStr }}</text>
        </view>
    </view>
</template>

<script>

import {updateLocationOnce, baseData} from './global';
import {
	formatDate,
	getDate,
	getLocalSolarTime,
	getTime,
} from './date';

let dateTimer = -1;

export default {
    name: 'showTime',
    props: [
    ],
    data() {
        return {
            localDateStr: '', // 当地时间
            localTimeStr: '', // 当地时间
            beijinDateStr: '', // 北京时间
            beijinTimeStr: '', // 北京时间
            sumRiseTimeStr: '', // 日出
            sumSetTimeStr: '', // 日落
        }
    },
    mounted() {
		updateLocationOnce();
		this.updateTime();
		clearInterval(dateTimer);
		dateTimer = setInterval(() => {
			this.updateTime();
		}, 1000);
	},
	unMounted() {
		clearInterval(dateTimer);
		dateTimer = -1;
	},
    methods: {
        updateTime() {
            this.beijinDateStr = getDate(baseData.beijin);
            this.beijinTimeStr = getTime(baseData.beijin);
            this.localDateStr = getDate(baseData.local);
            this.localTimeStr = getTime(baseData.local);
        },
        updateSun() {
			// if (longitude > 200) { // 说明还没初始化完成
			// 	if (longitude === 1001) {
			// 		this.localDateStr = '定位失败！';
			// 	} else {
			// 		this.localDateStr = '定位计算中...';
			// 	}
			// 	this.sumRiseTimeStr = '06:44';
			// 	this.sumSetTimeStr = '17:43';
			// 	return;
			// }

			// 30度44分30秒, 103度55分46秒   2025-2-10  7:48   18:47  30.74166667, 103.92944444
			// 39.9, 116.4
			// const result = calculateSunriseSunset(30.74166667, 103.92944444, new Date(), 500);
			// const result = calculateSunriseSunset(39.9, 116.4, new Date());
			// console.log('==_____', result);
			// this.sumRiseTimeStr = result.sunrise[0].toString().padStart(2, '0') + ':' + result.sunrise[1].toString().padStart(2, '0') ;
			// this.sumSetTimeStr = result.sunset[0].toString().padStart(2, '0') + ':' + result.sunset[1].toString().padStart(2, '0') ;
			// this.sumRiseTimeStr = '06:44';
			// this.sumSetTimeStr = '17:43';
		},
    }
}
</script>

<style lang="scss">
.local-bar {
    position: fixed;
    top: 5px;
    left: 5px;
    background-color: rgba(204, 204, 204, 0.6);
    padding: 0 5px;
    border-radius: 3px;

    .local-date {
        color: rgb(190, 172, 172);
        font-weight: bold;
        font-size: 13px;
        padding-right: 2px;
        letter-spacing: -1px;
    }

    .local-time {
        color: red;
        font-weight: bold;
    }

}

.sun-time {
    color: red;
    font-weight: bold;
}
</style>